﻿/*
	Class Description: this panel offers advanced tracing options for users.
	------------------------------------------------------------------------
	                          APACHE LICENSE
	------------------------------------------------------------------------
	Copyright 2010 Vu Thien Nguyen Phong
	
	Licensed under the Apache License, Version 2.0 (the "License");
	you may not use this file except in compliance with the License.
	You may obtain a copy of the License at
	
	http://www.apache.org/licenses/LICENSE-2.0
	
	Unless required by applicable law or agreed to in writing, software
	distributed under the License is distributed on an "AS IS" BASIS,
	WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
	See the License for the specific language governing permissions and
	limitations under the License.
*/

package com.minidebugger {
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	import flash.text.TextFormat;
	import flash.system.System;
	import flash.utils.getTimer;
	import flash.geom.Rectangle;
	import com.minidebugger.gui.Panel;
	import com.minidebugger.gui.VScrollBar;

	public class TracingPanel extends Sprite{
		// TracingPanel's constants
		private const PANEL_WIDTH:int = 300;
		private const PANEL_HEIGHT:int = 120;
		private const PANEL_TITLE:String = "MiniDebugger >>> Tracing Panel";
		
		// variables for DebugPanel class
		private var panel:Panel;
		private var content_txt:TextField; // the textbox displaying trace information
		private var scroll_mc:VScrollBar;
		
		public function TracingPanel() {
			addEventListener(Event.ADDED_TO_STAGE,init);
		}
		
		private function init(e:Event):void{
			removeEventListener(Event.ADDED_TO_STAGE,init);
			
			// entry point
			setupTracingPanel();
		}
		
		private function setupTracingPanel():void{
			// drawing the panel
			panel = new Panel(PANEL_TITLE,PANEL_WIDTH,PANEL_HEIGHT);
			addChild(panel);
			panel.x = 20;
			panel.y = 20;
			panel.buttonMode = true;
			
			// adding content textbox
			var content_tf:TextFormat = new TextFormat();
			content_tf.font = "Arial";
			content_tf.size = 11;
			
			content_txt = new TextField();
			content_txt.multiline = true;
			content_txt.wordWrap = true;
			content_txt.border = true;
			content_txt.borderColor = 0xffaaaaaa;
			content_txt.defaultTextFormat = content_tf;
			content_txt.x = 5;
			content_txt.y = 25;
			content_txt.width = PANEL_WIDTH - 30;
			content_txt.height = 90;
			panel.addChild(content_txt);
			
			// adding the scrollbar
			scroll_mc = new VScrollBar(content_txt);
			scroll_mc.x = content_txt.x + content_txt.width + 12;
			scroll_mc.y = content_txt.y;
			panel.addChild(scroll_mc);
		}
		
		public function trace(s:String):void{
			if (panel){
				content_txt.htmlText+= s+"\n";
				content_txt.scrollV = content_txt.maxScrollV;
				scroll_mc.updateScrollThumbPosition();
			}
		}
	}
}
